//
//  QHHomeVC.swift
//  QingHuWord
//
//  Created by 李东 on 2024/3/30.
//

import UIKit

class QHHomeVC: QHBaseVC {
    
    @IBOutlet weak var settingBtn_top: NSLayoutConstraint!
    
    @IBOutlet weak var bgView: UIView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        hideNavgaitionBar()
        settingBtn_top.constant = CGFloat.topPadding
        NotificationCenter.default.addObserver(self, selector: #selector(showAd), name: .SDKInitFinish, object: nil)
    }
    
    @objc func showAd() {
        if AppProducts.shared.isPurchased {
            adHelper.removeBannerView()
        }else{
            if hasLoadAd {
                return
            }
            hasLoadAd = true
            adHelper.loadBanner(currentVC: self, isMainVC: false)
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if ADManager.initFinish {
            showAd()
        }
    }
    
    

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        bgView.jw_corner(byRoundingCorners: [.topLeft, .topRight], radii: 25)
    }
    
    @IBAction func settingAction(_ sender: Any) {
        navigationController?.pushViewController(QHSetupVC(), animated: true)
    }
    
    @IBAction func openWebAction(_ sender: Any) {
        if !AppProducts.shared.isPurchased {
            showSubVC()
            return
        }
        navigationController?.pushViewController(QHWebVC(url: AppConfig.H5_URL), animated: true)
    }
    
    @IBAction func openRelax(_ sender: Any) {
        if !AppProducts.shared.isPurchased {
            showSubVC()
            return
        }
        navigationController?.pushViewController(QHRelaxVC(), animated: true)
    }
    
}
